]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Increase the timeout for hiding the tray if the mouse didn't move far from it
authorHellyna Ng <helly@helly.tk>
Sat, 30 Oct 2010 19:54:43 +0000 (03:54 +0800)
committerMarina Zhurakhinskaya <marinaz@redhat.com>
Sat, 30 Oct 2010 21:20:13 +0000 (17:20 -0400)
We shouldn't hide the tray as quickly if the user might have left it
unintentionally, such as when moving the mouse over to a different tray item or
using the scroll bar in the chat notification.

https://bugzilla.gnome.org/show_bug.cgi?id=630767

js/ui/messageTray.js

index e0561cb4c04c717429dcf9e6b40b0bdd499c81e3..7ab1b76d2a8ba89a3eddeefff450c72a6fa0ece2 100644 (file)
@@ -26,6 +26,10 @@ const BUTTON_ICON_SIZE = 36;
 
 const MAX_SOURCE_TITLE_WIDTH = 180;
 
+// We delay hiding of the tray if the mouse is within MOUSE_LEFT_ACTOR_THRESHOLD
+// range from the point where it left the tray.
+const MOUSE_LEFT_ACTOR_THRESHOLD = 20;
+
 const State = {
     HIDDEN:  0,
     SHOWING: 1,
@@ -1146,6 +1150,8 @@ MessageTray.prototype = {
             if (this._trayLeftTimeoutId) {
                 Mainloop.source_remove(this._trayLeftTimeoutId);
                 this._trayLeftTimeoutId = 0;
+                this._trayLeftMouseX = -1;
+                this._trayLeftMouseY = -1;
                 return;
             }
 
@@ -1167,6 +1173,14 @@ MessageTray.prototype = {
             this._pointerInTray = true;
             this._updateState();
         } else {
+            // We record the position of the mouse the moment it leaves the tray. These coordinates are used in
+            // this._onTrayLeftTimeout() to determine if the mouse has moved far enough during the initial timeout for us
+            // to consider that the user intended to leave the tray and therefore hide the tray. If the mouse is still
+            // close to its previous position, we extend the timeout once.
+            let [x, y, mods] = global.get_pointer();
+            this._trayLeftMouseX = x;
+            this._trayLeftMouseY = y;
+
             // We wait just a little before hiding the message tray in case the user quickly moves the mouse back into it.
             // We wait for a longer period if the notification popped up where the mouse pointer was already positioned.
             // That gives the user more time to mouse away from the notification and mouse back in in order to expand it.
@@ -1176,12 +1190,25 @@ MessageTray.prototype = {
     },
 
     _onTrayLeftTimeout: function() {
-        this._useLongerTrayLeftTimeout = false;
-        this._trayLeftTimeoutId = 0;
-        this._pointerInTray = false;
-        this._pointerInSummary = false;
-        this._updateNotificationTimeout(0);
-        this._updateState();
+        let [x, y, mods] = global.get_pointer();
+        // We extend the timeout once if the mouse moved no further than MOUSE_LEFT_ACTOR_THRESHOLD to either side or up.
+        // We don't check how far down the mouse moved because any point above the tray, but below the exit coordinate,
+        // is close to the tray.
+        if (this._trayLeftMouseX > -1 &&
+            y > this._trayLeftMouseY - MOUSE_LEFT_ACTOR_THRESHOLD &&
+            x < this._trayLeftMouseX + MOUSE_LEFT_ACTOR_THRESHOLD &&
+            x > this._trayLeftMouseX - MOUSE_LEFT_ACTOR_THRESHOLD) {
+            this._trayLeftMouseX = -1;
+            this._trayLeftTimeoutId = Mainloop.timeout_add(LONGER_HIDE_TIMEOUT * 1000,
+                                                             Lang.bind(this, this._onTrayLeftTimeout));
+        } else {
+            this._trayLeftTimeoutId = 0;
+            this._useLongerTrayLeftTimeout = false;
+            this._pointerInTray = false;
+            this._pointerInSummary = false;
+            this._updateNotificationTimeout(0);
+            this._updateState();
+        }
         return false;
     },